/*
 * Copyright (C) 2009 Georgios J. Georgopoulos, All rights reserved.
 * 
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
 * site: http://www.fsf.org.
 */
package org.gwt.mosaic.xul.client.ui;

import org.gwt.mosaic.actions.client.ActionBindings;

import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Widget;

/**
 * A single choise in a menupopup element. It acts much like a button but it is
 * rendered on a menu.
 * 
 * @author georgopoulos.georgios(at)gmail.com
 * 
 */
public class Menuitem extends Element {
  private static final long serialVersionUID = 5773153820405079698L;

  // -----------------------------------------------------------------------
  /**
   * Indicates whether the element is checked or not.
   * 
   * NOTE: The {@code checked} attribute requires {@code command} attribute to
   * be set.
   */
  public static final String CHECKED = "checked";

  public boolean getChecked() {
    return getBoolean(CHECKED);
  }

  public void setChecked(boolean checked) {
    putBoolean(CHECKED, checked);
  }

  // -----------------------------------------------------------------------
  /**
   * Set to the id of a command element that is being observed by the element.
   */
  public static final String COMMAND = "command";

  public String getCommand() {
    return getString(COMMAND);
  }

  public void setCommand(String command) {
    putString(COMMAND, command);
  }

  // -----------------------------------------------------------------------
  /**
   * The label that will appear on the element. If this is left out, no text
   * appears.
   */
  public static final String LABEL = "label";

  public String getLabel() {
    return getString(LABEL);
  }

  public void setLabel(String label) {
    putString(LABEL, label);
  }

  // -----------------------------------------------------------------------
  /**
   * Radio menuitems with the same name as put into a group. Only one menuitem
   * in each radio group can be checked at a time..
   */
  public static final String NAME = "name";

  public String getName() {
    return getString(NAME);
  }

  public void setName(String name) {
    putString(NAME, name);
  }

  // -----------------------------------------------------------------------
  /**
   * Can be used to create checkable menuitems or radio button menuitems.
   * 
   * <ul>
   * <li>{@code checkbox}: The menuitem is checked.</li>
   * <li>{@code radio}: The menuitem is radio.</li>
   * </ul>
   * 
   * NOTE: The {@code type} attribute requires {@code command} attribute to be
   * set.
   */
  public static final String TYPE = "type";

  public String getType() {
    return getString(TYPE);
  }

  public void setType(String type) {
    putString(TYPE, type);
  }

  // -----------------------------------------------------------------------
  private transient MenuItem menuItem;

  /**
   * @return the menuItem
   */
  protected MenuItem getMenuItem() {
    return menuItem;
  }

  /**
   * @param menuItem the menuItem to set
   */
  protected void setMenuItem(MenuItem menuItem) {
    this.menuItem = menuItem;
  }

  // -----------------------------------------------------------------------
  private transient ActionBindings<MenuItem> menuItemBindings;

  /**
   * @return the menuItemBindings
   */
  protected ActionBindings<MenuItem> getMenuItemBindings() {
    return menuItemBindings;
  }

  /**
   * @param menuItemBindings the menuItemBindings to set
   */
  protected void setMenuItemBindings(ActionBindings<MenuItem> menuItemBindings) {
    this.menuItemBindings = menuItemBindings;
  }

  // -----------------------------------------------------------------------
  public Menuitem() {
    super();
  }

  // -----------------------------------------------------------------------
  @Override
  protected Widget createUI() {
    return null;
  }

}
